﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace zp.mk.tmpBasket
{
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        struct Datensatz
        {
            public string sArtikelnummer;
            public int iAnzahl;
            public float fEinzelpreis;
            public float fRabatt;
            public float fPosition;
        }

        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnGo_Click(object sender, RoutedEventArgs e)
        {

            Datensatz[] positionen = new Datensatz[10];

            int pointer = 0;

            string sOut = "";

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Logdateien (*.log*)|*.log|Textdateien (*.txt)|*.txt";

            if((bool)ofd.ShowDialog())
            {
                StreamReader sr = new StreamReader(ofd.FileName);
                while(!sr.EndOfStream)
                {
                    string[] Data = sr.ReadLine().Split(';');
                    positionen[pointer].sArtikelnummer = Data[0];
                    positionen[pointer].iAnzahl = Int32.Parse(Data[1]);
                    positionen[pointer].fEinzelpreis = float.Parse(Data[2]);
                    positionen[pointer].fRabatt = float.Parse(Data[3]);
                    positionen[pointer].fPosition = (positionen[pointer].fEinzelpreis - (positionen[pointer].fEinzelpreis * positionen[pointer].fRabatt / 100)) * positionen[pointer].iAnzahl;
                    pointer++;
                }

                foreach(Datensatz position in positionen)
                {
                    sOut += position.sArtikelnummer + "\t" + position.iAnzahl.ToString() + "\t" + Math.Round(position.fEinzelpreis, 2).ToString() + "\t" + Math.Round(position.fRabatt, 2).ToString() + "\t" + Math.Round(position.fPosition, 2).ToString() + "\r\n";
                }
                txtBox.Text = sOut;
            }
        }
    }
}
